package ModelLayer;
import ControlLayer.*;
import java.util.ArrayList;
import ModelLayer.*;

public class Person
{
    private long id;
    private String name;
    private String address;
    private String postalCode;
    private String city;
    private String phone;
    DvdContainer dvdContainer;
    private ArrayList<Copy> copies;


 



   public Person(long id, String name, String address, String postalCode, String city, String phone)
   {
       this.id = id;
       this.name = name;
       this.address = address;
       this.postalCode = postalCode;
       this.city = city;
       this.phone = phone;
       copies = new ArrayList<Copy> ();
    }
  

    public String getAddress()

    {
        return address;
    }


    public void setName(String newName)
    {
        name = newName;
    }
   public void setAddress (String newAddress)
   {
       address = newAddress;

   }
public long getId()
    {
        return id;
    }
    public String getName()
    { 
        return name;
        
    }
    public void addCopyToThePerson(int serialNumber, String purchaseDate, double price)
    {

        Copy copy = new Copy(serialNumber, purchaseDate, price);
        copies.add(copy);
        }
        
    
    public int showNumberOfCopies()
    {
        
        return copies.size();
}
public Copy findCopy(int id, int serialNumber)
{
    DVD dvd = dvdContainer.findDVD(id);
    if(dvdContainer.findDVD(id) == null)
    {
        System.out.println("There is no dvd with this id");
        return null;
    }
    else
    {
        dvd.findCopy(serialNumber);
        if(dvd.findCopy(serialNumber) == null)
        {
            System.out.println("There is no dvd with this id");
            return null;
        }
        else
        {
            Copy copy = dvd.findCopy(serialNumber);
            return copy;
        }}
    }
public void showIformationAboutCopies()
{
    if(showNumberOfCopies() != 0)
{
    System.out.println("This person has " + copies.size() + " copies of films");
    for(Copy copy: copies)
        {
            copy.getInformationAboutCopysDVD();
            System.out.println("Serial number of copy is " + copy.getSerialNumber());
            System.out.println("Purchase date of copy is " + copy.getPurchaseDate());
            System.out.println("Purchase price of copy was " + copy.getPurchasePrice());
        }}}
        public void removeCopy(int serialNumber)
    {
        Copy copy = findCopy(serialNumber);
        copies.remove(copy);
}
    public Copy findCopy(int serialNumber)
    {
        boolean found= false;
        int index=0;
        while(index < copies.size() && !found)
        {
            Copy copy= copies.get(index);
            if(copy.getSerialNumber() == serialNumber)
            {
                found = true;
            }
            else{
                index++;
            }
        }//end while
        if(found) {
            return copies.get(index);
        }
        else{
            return null;
        }
    }}
            

